package org.westos.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.westos.pojo.ChuFang;
import org.westos.pojo.ChuFangYao;
import org.westos.pojo.ChufangDto;
import org.westos.pojo.ShowChu;
import org.westos.service.ChufangService;
import org.westos.service.YaoService;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ChufangController {

    @Autowired
    private ChufangService chu_service;
    @Autowired
    private YaoService yao_service;

    @RequestMapping("AllChu")
    public String ShowChus(Model model) {
        List<ShowChu> showChus = chu_service.queryByDoc("王大夫");
        model.addAttribute("chus", showChus);
        return "";
    }

    @RequestMapping("toAddChu")
    public String toAddChu(Model model) {
        return "AddChu";
    }

    @RequestMapping("chuAdd")
    public String AddChu(ChufangDto cfy) {
        cfy.getChufang().setDate_time(null);
        cfy.getChufang().setPrescription_id(null);
        cfy.getChufang().setPrescription_num(null);
        List<ChuFangYao> chuFangYaoList = cfy.getChuFangYaoList();
        for (ChuFangYao chuFangYao : chuFangYaoList) {
            chuFangYao.setPrescription_id(cfy.getChufang().getPrescription_id());
            chuFangYao.setAll_name(null);
            System.out.println(chuFangYao.getDrugs_id());
        }
        System.out.println(cfy.getChufang().getPhone());
//        chu_service.addChu(cfy);
        return "hello";
    }

}
